﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Kocic.RepositoryManagement.SystemFile;

namespace Sample.Run.SystemFile
{
    public class PersonLineObject : LineObject
    {
        private String _firstName;
        private String _lastName;
        private String _age;

        public String FirstName
        {
            get
            {
                if (String.IsNullOrEmpty(this._firstName))
                {
                    this._firstName = this.Contents.Split(',')[0];
                }
                
                return this._firstName;
            }
        }

        public String LastName
        {
            get
            {
                if (String.IsNullOrEmpty(this._lastName))
                {
                    this._lastName = this.Contents.Split(',')[1];
                }

                return this._lastName;
            }
        }

        public String Age
        {
            get
            {
                if (String.IsNullOrEmpty(this._age))
                {
                    this._age = this.Contents.Split(',')[2];
                }

                return this._age;
            }
        }

        public PersonLineObject()
        {

        }

        public PersonLineObject(String firstName, String lastName, String age)
        {
            this._firstName = firstName;
            this._lastName = lastName;
            this._age = age;

            this.BuildContents();
        }

        protected override void BuildContents()
        {
            StringBuilder builder = new StringBuilder();
            builder.Append(this._firstName);
            builder.Append(",");
            builder.Append(this._lastName);
            builder.Append(",");
            builder.Append(this._age);

            this.Contents = builder.ToString();
        }
    }
}
